//
//  ToResiduePayViewController.m
//  HAODE
//
//  Created by panquanReabam.com on 15/9/26.
//  Copyright (c) 2015年 reabam.com. All rights reserved.
#import "CashierViewController.h"
#import "RDVTabBarController.h"
#import "AttributedLabel.h"
#import "UIViewExt.h"
#import "HttpRequest.h"
#import "ServiceListViewController.h"
#import "OrderListViewController.h"
#import "QRCodeGenerator.h"
#import "UIButton+WebCache.h"
#import "GatheringDetailViewController.h"
#import "UIImage+RTTint.h"
#import "MemberListViewController.h"
#import "GatheringListViewController.h"
#import "TheKeyboardView.h"
@interface CashierViewController ()<UIScrollViewDelegate,UIGestureRecognizerDelegate,MemberListViewControllerDelegate,TheKeyboardViewDelegate>
@end
@implementation CashierViewController
{
    UIScrollView*myscrollView;
    UIButton*tureBtn;
    NSString *payType;
    NSString *payTypeName;
    UIButton *time;
    NSString*payTypeStr;
    UIView*reproductionView;
    UIImageView*chaimageView;
    UIView*addView;
    BOOL saveAccount;
    NSString*Token;
    UIView*NOView;
    TheKeyboardView*KeyboardView;
}
@synthesize alt = alt;
-(void)BackAction:(UIButton *)sender{
    [time removeFromSuperview];
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden=YES;
    [[self rdv_tabBarController] setTabBarHidden:YES];
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    Token = [user objectForKey:@"tokenId"];
    saveAccount=YES;
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    [[UINavigationBar appearance] setBarTintColor:[UIColor whiteColor]];
}
-(void)loadingtitle{
   UIView*naviView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 64)];
    naviView.backgroundColor=[UIColor colorWithRed:14/255.0 green:23/255.0 blue:0/255.0 alpha:1.0];
    [self.view addSubview:naviView];
    UIImage *img=[UIImage imageNamed:@"tianjia"];
    UIImage *tinted = [img rt_tintedImageWithColor:[UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0] ];
    UIButton*editorBtn = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth-45, 27.5, 30, 30)];
    [editorBtn setImage:tinted forState:UIControlStateNormal];
    [editorBtn addTarget:self action:@selector(tianjia:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:editorBtn];
    UIImage* backImage = [UIImage imageNamed:@"fanhui"];
    CGRect backframe = CGRectMake(10,27.5,30,30);
    UIButton*backButton= [[UIButton alloc] initWithFrame:backframe];
    [backButton setBackgroundImage:backImage forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(BackAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:backButton];
    UILabel*titleStr=[[UILabel alloc]initWithFrame:CGRectMake(0, 10, ScreenWidth, 64)];
    titleStr.text=@"收银";
    titleStr.textColor=[UIColor whiteColor];
    titleStr.font=[UIFont systemFontOfSize:18];
    titleStr.textAlignment=NSTextAlignmentCenter;
    [self.view addSubview:titleStr];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadingtitle];
    [self cashier];
    self.orderId=@"";
    self.memberId=@"";
    self.memberName=@"";
    self.orderType=@"other";
}
//other收银
-(void)cashier{
    KeyboardView=[[TheKeyboardView alloc]initWithFrame:CGRectMake(0, 64, ScreenWidth, ScreenHeight)];
    KeyboardView.mDelegate=self;
    [self.view addSubview:KeyboardView];
    }
//现金收银
- (void)cashBtn:(NSString *)str{
    [myscrollView removeFromSuperview];
    [reproductionView removeFromSuperview];
    [chaimageView removeFromSuperview];
    if ([KeyboardView.wufuhaopayAmount.text isEqualToString:@"0.00"]) {
        [self showAlertMessage:@"收款金额不能为0"];
    }else{
        
        if ([KeyboardView.payAmount.text isEqualToString:@"0.00"]) {
            [self showAlertMessage:@"收款金额不能为0"];
        }else{
            payType=@"C";
            [self cashBtn];
        }
    }
}
- (void)creditCardBtn:(NSString *)str{
    [self showAlertMessage:@"未开通！"];
}
//支付宝微信收银
- (void)payTreasure:(NSString *)strPay{
    
    if ([KeyboardView.wufuhaopayAmount.text isEqualToString:@"0.00"]) {
        [self showAlertMessage:@"收款金额不能为0"];
    }else{
        
        if ([KeyboardView.payAmount.text isEqualToString:@"0.00"]) {
            [self showAlertMessage:@"收款金额不能为0"];
        }else{
            if ([strPay isEqualToString:@"AliQrPay"]) {
               payTypeName=@"支付宝支付";
                           }
            if ([strPay isEqualToString:@"WxScanPay"]) {
                payTypeName=@"微信支付";
                }
            [myscrollView removeFromSuperview];
            [reproductionView removeFromSuperview];
            [chaimageView removeFromSuperview];
            reproductionView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight+60)];
            reproductionView.backgroundColor=backColor;
            reproductionView.alpha=0.6;
            [self.view addSubview:reproductionView];
            UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeKeyBoad)];
            singleFingerOne.numberOfTouchesRequired = 1; //手指数
            singleFingerOne.numberOfTapsRequired = 1; //tap次数
            singleFingerOne.delegate = self;
            [reproductionView addGestureRecognizer:singleFingerOne];
            myscrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,KeyboardView.payAmount.bottom+64-0.5, ScreenWidth, ScreenWidth)];
            [myscrollView setBackgroundColor: [UIColor whiteColor]];
            [self.view addSubview:myscrollView];
            NSMutableDictionary *params = [NSMutableDictionary new];
            [params setValue:Token forKey:@"tokenId"];
            [params setValue:self.orderType forKey:@"orderType"];
            [params setValue:self.orderId  forKey:@"orderId"];
            [params setValue:self.memberId forKey:@"memberId"];
            [params setValue:self.memberName  forKey:@"memberName"];
            [params setValue:[NSString stringWithFormat:@"%.2f",  [KeyboardView.wufuhaopayAmount.text doubleValue]] forKey:@"payAmount"];
            [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        [HttpRequest requestData:[NSString stringWithFormat:@"Business/Pay/%@",strPay] params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
                if (isSuccess) {
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
               
                        [Global hideProgressHUDInternal:self.view];
                        self.gid=[severDataDict.dataDict objectForKey:@"gid"];
                        [self times];
                        [self str:payTypeName priceStr:KeyboardView.payAmount.text QRStr:[severDataDict.dataDict  objectForKey:@"qrCode"]];
                        }else{
                        [Global hideProgressHUDInternal:self.view];
                        NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                        [Global showTextHudSub:requestResultStr view:self.view];
                    }}
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    [Global showTextHudSub:@"连接失败" view:self.view];
                }
                
            }];
            
        }
        chaimageView=[[UIImageView alloc]initWithFrame:CGRectMake(ScreenWidth-50, KeyboardView.payAmount.bottom+64-15, 30, 30)];
        chaimageView .image=[UIImage imageNamed:@"chas"];
        [self.view addSubview:chaimageView];
    }
}

-(void)str:(NSString*)String priceStr:(NSString*)priceStr QRStr:(NSString*)QRStr{
    NSString *s12 = [NSString stringWithFormat:@"%@",  @"你选择"];
    UIFont *font12 = [UIFont systemFontOfSize:15];
    CGSize size12 = CGSizeMake(320, 2000);
    CGSize labelsize12 = [s12 sizeWithFont:font12 constrainedToSize:size12 lineBreakMode:NSLineBreakByCharWrapping];
    UILabel*label1=[[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth/2-100, 27, labelsize12.width, 15)];
    label1.text=[NSString stringWithFormat:@"%@",@"你选择"];
    label1.textColor=[UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1];
    label1.font=[UIFont systemFontOfSize:15];
    [myscrollView addSubview:label1];
    NSString *s1 = [NSString stringWithFormat:@"%@",  String];
    UIFont *font1= [UIFont systemFontOfSize:15];
    CGSize size1= CGSizeMake(320, 2000);
    CGSize labelsize1= [s1 sizeWithFont:font1 constrainedToSize:size1 lineBreakMode:NSLineBreakByCharWrapping];
    UILabel*label2=[[UILabel alloc]initWithFrame:CGRectMake(label1.right+5, 27, labelsize1.width+10, 15)];
    label2.text=[NSString stringWithFormat:@"%@",String];
    label2.backgroundColor=[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:1];
    label2.textColor=[UIColor whiteColor];
    label2.textAlignment=NSTextAlignmentCenter;
    label2.font=[UIFont systemFontOfSize:14];
    [myscrollView addSubview:label2];
    UILabel*label3=[[UILabel alloc]initWithFrame:CGRectMake(label2.right+5, 27, 100, 15)];
    label3.text=[NSString stringWithFormat:@"%@",@"需付金额:"];
    label3.textColor=[UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1];
    label3.font=[UIFont systemFontOfSize:15];
    [myscrollView addSubview:label3];
    UILabel*payAmounts=[[UILabel alloc]initWithFrame:CGRectMake(0, label1.bottom+7.5, ScreenWidth, 24)];
    payAmounts.text=[NSString stringWithFormat:@"%@",KeyboardView.payAmount.text];
    payAmounts.textColor=[UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1];
    payAmounts.textAlignment=NSTextAlignmentCenter;
    payAmounts.font=[UIFont systemFontOfSize:24];
    
    NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@",KeyboardView.payAmount.text]];
    [AttributedStr addAttribute:NSFontAttributeName
     
                          value:[UIFont systemFontOfSize:14]
     
                          range:NSMakeRange(0, 1)];
    
    [AttributedStr addAttribute:NSForegroundColorAttributeName
     
                          value:[UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1]
     
                          range:NSMakeRange(0, 1)];
    payAmounts.attributedText = AttributedStr;
    
    [myscrollView addSubview:payAmounts];
    tureBtn = [[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth/2-75, payAmounts.bottom+132/2, 150, 150)];
    [tureBtn setImageWithURL:[NSURL URLWithString:QRStr]];
    tureBtn.contentMode = UIViewContentModeScaleAspectFit;
    [myscrollView addSubview:tureBtn];
    [myscrollView setContentSize:CGSizeMake(ScreenWidth, tureBtn.bottom+60)];
    
}
//自动更新
- (void)times{
    time = [[UIButton alloc]init];
    time.frame = CGRectMake(ScreenWidth-100,ScreenHeight*35/2200,30,16);
    [time setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];
    [time setTitle:[NSString stringWithFormat:@"%d",10] forState:UIControlStateNormal];
    time.titleLabel.font = [UIFont boldSystemFontOfSize:16];
    [myscrollView addSubview:time];
    [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(countDownActions:) userInfo:time repeats:YES];
    
    
}
-(void)countDownActions:(NSTimer*)timer{
    
    time = timer.userInfo;
    
    if (!time.superview) {
        [timer invalidate];
        return;
    }
    int currentTime = [[time titleForState:UIControlStateNormal] intValue];
    [time setTitle:[NSString stringWithFormat:@"%d",--currentTime] forState:UIControlStateNormal];
    time.titleLabel.font = [UIFont systemFontOfSize:16];
    if (currentTime<1) {
        
        [time setTitle:[NSString stringWithFormat:@"%d",10] forState:UIControlStateNormal];
        [self times];
        [time removeFromSuperview];
        
        NSMutableDictionary *params = [NSMutableDictionary new];
        [params setValue:Token forKey:@"tokenId"];
        [params setValue:self.gid forKey:@"gid"];
        NSLog(@"%@",params);
        
        [HttpRequest requestData:@"Business/Gathering/Detail" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    
                    if ([[NSString stringWithFormat:@"%@",   [severDataDict.dataDict  objectForKey:@"status"]] isEqualToString:@"N"]) {
                        
                    }if ([[NSString stringWithFormat:@"%@",   [severDataDict.dataDict  objectForKey:@"status"]] isEqualToString:@"Y"]) {
                        [time removeFromSuperview];
                        [timer invalidate];
                        [self emptyView];
                        GatheringDetailViewController *detailViewController = [[GatheringDetailViewController alloc] init];
                        [self.navigationController pushViewController:detailViewController animated:YES];
                        }
                    }else{
                    }
        }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [timer invalidate];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
            
        }];}
}

//现金支付//刷卡支付//现金直接收银
-(void)cashBtn{
   [myscrollView removeFromSuperview];
    [chaimageView removeFromSuperview];
    reproductionView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight+60)];
    reproductionView.backgroundColor=backColor;
    reproductionView.alpha=0.6;
    [self.view addSubview:reproductionView];
    UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeKeyBoad)];
    singleFingerOne.numberOfTouchesRequired = 1; //手指数
    singleFingerOne.numberOfTapsRequired = 1; //tap次数
    singleFingerOne.delegate = self;
    [reproductionView addGestureRecognizer:singleFingerOne];
    myscrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,KeyboardView.payAmount.bottom+64-0.5, ScreenWidth, ScreenWidth)];
    [myscrollView setBackgroundColor: [UIColor whiteColor]];
    [self.view addSubview:myscrollView];
    if ([payType isEqualToString:@"C"]) {
        payTypeStr=@"现金支付";
    }
    if ([payType isEqualToString:@"B"]) {
        payTypeStr=@"刷卡支付";
    }
    NSString *s12 = [NSString stringWithFormat:@"%@",  @"你选择"];
    UIFont *font12 = [UIFont systemFontOfSize:15];
    CGSize size12 = CGSizeMake(320, 2000);
    CGSize labelsize12 = [s12 sizeWithFont:font12 constrainedToSize:size12 lineBreakMode:NSLineBreakByCharWrapping];
    UILabel*label1=[[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth/2-100, height5or6, labelsize12.width, 15)];
    label1.text=[NSString stringWithFormat:@"%@",@"你选择"];
    label1.textColor=[UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1];
    label1.font=[UIFont systemFontOfSize:15];
    [myscrollView addSubview:label1];
    NSString *s1 = [NSString stringWithFormat:@"%@",  payTypeStr];
    UIFont *font1= [UIFont systemFontOfSize:15];
    CGSize size1= CGSizeMake(320, 2000);
    CGSize labelsize1= [s1 sizeWithFont:font1 constrainedToSize:size1 lineBreakMode:NSLineBreakByCharWrapping];
    UILabel*label2=[[UILabel alloc]initWithFrame:CGRectMake(label1.right+5, height5or6, labelsize1.width+10, 15)];
    label2.text=[NSString stringWithFormat:@"%@",payTypeStr];
    label2.backgroundColor=[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:1];
    label2.textColor=[UIColor whiteColor];
    label2.textAlignment=NSTextAlignmentCenter;
    label2.font=[UIFont systemFontOfSize:14];
    [myscrollView addSubview:label2];
    UILabel*label3=[[UILabel alloc]initWithFrame:CGRectMake(label2.right+5, height5or6, 100, 15)];
    label3.text=[NSString stringWithFormat:@"%@",@"需付金额:"];
    label3.textColor=[UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1];
    label3.font=[UIFont systemFontOfSize:15];
    [myscrollView addSubview:label3];
    UILabel*payAmounts=[[UILabel alloc]initWithFrame:CGRectMake(0, label1.bottom+7.5, ScreenWidth, 24)];
    payAmounts.text=[NSString stringWithFormat:@"%@",KeyboardView.payAmount.text];
    payAmounts.textColor=[UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1];
    payAmounts.textAlignment=NSTextAlignmentCenter;
    payAmounts.font=[UIFont systemFontOfSize:24];
    NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@",KeyboardView.payAmount.text]];
    
    [AttributedStr addAttribute:NSFontAttributeName
     
                          value:[UIFont systemFontOfSize:14]
     
                          range:NSMakeRange(0, 1)];
    
    [AttributedStr addAttribute:NSForegroundColorAttributeName
     
                          value:[UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1]
     
                          range:NSMakeRange(0, 1)];
    payAmounts.attributedText = AttributedStr;
    
    [myscrollView addSubview:payAmounts];
    tureBtn = [[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth/2-50, payAmounts.bottom+80, 215/2,  215/2)];
    tureBtn.layer.masksToBounds = YES;
    tureBtn.backgroundColor= luseColor;
    tureBtn.layer.cornerRadius =  215/2/2;
    [tureBtn setTitle:@"确认" forState:UIControlStateNormal];
    [tureBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [tureBtn addTarget:self action:@selector(ture:) forControlEvents:UIControlEventTouchUpInside];
    tureBtn.layer.borderColor = [UIColor whiteColor].CGColor;
    tureBtn.layer.borderWidth = 0;
    tureBtn.contentMode = UIViewContentModeScaleAspectFit;
    tureBtn.titleLabel.font=[UIFont systemFontOfSize:18];
    [myscrollView addSubview:tureBtn];
    [myscrollView setContentSize:CGSizeMake(ScreenWidth, tureBtn.bottom+60)];
    chaimageView=[[UIImageView alloc]initWithFrame:CGRectMake(ScreenWidth-50, KeyboardView.payAmount.bottom+64-15, 30, 30)];
    chaimageView .image=[UIImage imageNamed:@"chas"];
    [self.view addSubview:chaimageView];
}
- (void)ture:(UIButton *)button{
    NSMutableDictionary *params = [NSMutableDictionary new];
    [params setValue:Token forKey:@"tokenId"];
    [params setValue:self.orderType forKey:@"orderType"];
    [params setValue:self.orderId  forKey:@"orderId"];
    [params setValue:self.memberId forKey:@"memberId"];
    [params setValue:self.memberName  forKey:@"memberName"];
    [params setValue:[NSString stringWithFormat:@"%.2f",  [KeyboardView.wufuhaopayAmount.text doubleValue]] forKey:@"payAmount"];
    [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:20 view:self.view];
    [HttpRequest requestData:@"Business/Pay/CashPay" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                [self showAlertMessage:@"收银成功！"];
                [self emptyView];
            }else{
                [Global hideProgressHUDInternal:self.view];
                NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                [Global showTextHudSub:requestResultStr view:self.view];
            }}
        else
        {
            [Global hideProgressHUDInternal:self.view];
            [Global showTextHudSub:@"连接失败" view:self.view];
        }
        
    }];
}
- (void)showAlertWait
{
    alt = [[UIAlertView alloc] initWithTitle:@"网络不稳定 ！" message:@"请确认网络" delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
    
}
- (void)showAlertMessage:(NSString *)msg
{
    alt = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:msg delegate:nil cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
}
- (void)hideAlert
{
    if (alt != nil)
    {
        [alt dismissWithClickedButtonIndex:0 animated:YES];
        alt = nil;
    }
}
-(void)tianjia:(UIButton *)sender{
    [addView removeFromSuperview];
    saveAccount=! saveAccount;
    if (!saveAccount) {
        addView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
        addView.backgroundColor=[UIColor clearColor];
        [self.view addSubview:addView];
        UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeKeyBoad1)];
        singleFingerOne.numberOfTouchesRequired = 1; //手指数
        singleFingerOne.numberOfTapsRequired = 1; //tap次数
        singleFingerOne.delegate = self;
        [addView addGestureRecognizer:singleFingerOne];
        UIView*addV=[[UIView alloc]initWithFrame:CGRectMake(ScreenWidth-185, 64, 170, 336/2)];
        addV.backgroundColor=[UIColor colorWithRed:40/255.0 green:65/255.0 blue:1/255.0 alpha:1.0];
        addV.alpha=0.94;
        [addV.layer setCornerRadius:3.0]; //设置矩圆角半径
        [addV.layer setBorderWidth:0.3];   //边框宽度
        CGColorSpaceRef tureBTnSpace = CGColorSpaceCreateDeviceRGB();
        CGColorRef tureBTncolorref = CGColorCreate(tureBTnSpace,(CGFloat[]){40/255.0,65/255.0, 1/255.0, 1.0});
        [addV.layer setBorderColor:tureBTncolorref];//边框颜色
        [addView addSubview:addV];
        UIImage *img=[UIImage imageNamed:@"xialajiantou"];
        UIImageView*imageview=[[UIImageView alloc]initWithFrame:CGRectMake(ScreenWidth-35, 64-3.5, 10, 3.5)];
        imageview.image=img;
        imageview.alpha=1;
        [addView addSubview:imageview];
        NSArray *buttonContent = @[@"     会员",@"            未付订单",@"            历史账单"];
        NSArray *buttonContentimage = @[@"shouyin_huiyuan",@"weifudingdan",@"shouyin_lishizhangdan"];
        for (int i = 0;  i<3; i++) {
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            button.frame = CGRectMake(0, 2.5+336/2/3*i, 170, 50);
            [button setTitle:[buttonContent objectAtIndex:i] forState:UIControlStateNormal];
            button.titleLabel.font=[UIFont systemFontOfSize:15];
            button.contentHorizontalAlignment=UIControlContentHorizontalAlignmentCenter;
            [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
            button.tag = i+1;
            button.alpha=0.88;
            [addV addSubview:button];
            UIButton *shanghubutton = [UIButton buttonWithType:UIButtonTypeCustom];
            shanghubutton.frame = CGRectMake(35, 7.5+336/2/3*i, 40, 40);
            [shanghubutton setBackgroundImage:[UIImage imageNamed:[buttonContentimage objectAtIndex:i]] forState:UIControlStateNormal];
            [addV addSubview:shanghubutton];
            if (i==0) {
                }else{
                UILabel*line=[[UILabel alloc]initWithFrame:CGRectMake(10, 336/2/3*i, 170-20, 0.35)];
                line.backgroundColor=luseColor;
                [addV addSubview:line];
            }}
    }else{
            [addView removeFromSuperview];
}}
- (void)buttonAction:(UIButton *)button{
    saveAccount=YES;
    [addView removeFromSuperview];
    switch (button.tag)
    {
        case 1:
            if (button.tag==1) {
                KeyboardView.wufuhaopayAmount.text=@"0.00";
                KeyboardView.payAmount.text=@"0.00";
                MemberListViewController*de = [[MemberListViewController alloc] init];
                de.chooseState=@"选择";
                de.delegate=self;
                [self.navigationController pushViewController:de animated:YES];
                }
            break;
            
        case 2:
            if (button.tag==2) {
                OrderListViewController*de = [[OrderListViewController alloc] init];
                de.chooseState=@"选择";
                de.filterNPay=@"1";
                [self.navigationController pushViewController:de animated:YES];
            }
            break;
        case 3:
            if (button.tag==3) {
                GatheringListViewController *detailViewController = [[GatheringListViewController alloc] init];
                [self.navigationController pushViewController:detailViewController animated:YES];
                }
            
            break;
        default:
            break;
    }
}

- (void)secondViewController:(MemberListViewController *)secondViewController
                 memberIdStr:(NSString *)memberIdStr userName:(NSString *)userName phone:(NSString *)phone sex:(NSString *)sex consigneeName:(NSString *)consigneeName consigneeAddr:(NSString *)consigneeAddr consigneePhone:(NSString *)consigneePhone{
    self.orderType=@"other";
    self.orderId=@"";
    self.memberId=memberIdStr;
    self.memberName=userName;
    [NOView removeFromSuperview];
    NOView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 40+65)];
    NOView.backgroundColor=[UIColor clearColor];
    [self.view addSubview:NOView];
    UILabel*orderNo=[[UILabel alloc]initWithFrame:CGRectMake(0,65+15, ScreenWidth,16)];
    orderNo.textColor=luseColor;
    orderNo.backgroundColor=[UIColor colorWithRed:14/255.0 green:23/255.0 blue:0/255.0 alpha:1.0];
    orderNo.font=[UIFont boldSystemFontOfSize:14];
    [NOView addSubview:orderNo];
    orderNo.text=[NSString stringWithFormat:@"    会员 %@ （%@）",  userName,phone];
    KeyboardView.shu.text = @"";
    KeyboardView.jiajianhao.text=@"0.00";
}

-(void)closeKeyBoad1
{   saveAccount=YES;
    [addView removeFromSuperview];
}
-(void)emptyView{
    KeyboardView.shu.text = @"";
    self.orderId=@"";
    self.memberId=@"";
    self.memberName=@"";
    self.orderType=@"other";
    KeyboardView.wufuhaopayAmount.text=@"0.00";
    KeyboardView.payAmount.text=@"0.00";
    KeyboardView.jiajianhao.text=@"0.00";
    [self closeKeyBoad];
}
-(void)closeKeyBoad
{
    [KeyboardView.weChatBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [KeyboardView.payTreasureBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [KeyboardView.creditCardBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [KeyboardView.cashBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [myscrollView removeFromSuperview];
    [NOView removeFromSuperview];
    [reproductionView removeFromSuperview];
    [chaimageView removeFromSuperview];
    [time removeFromSuperview];
}

@end
